home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / pp / pp-6.0 / Format / asn / asn_charset.c next >
Encoding:
C/C++ Source or Header  |  1991-12-18  |  1.9 KB  |  98 lines

  1. /* asn_charset.c - calls strncnv to perform the character set conversions */
  2.  
  3. # ifndef lint
  4. static char Rcsid[] = "@(#)$Header: /xtel/pp/pp-beta/Format/asn/RCS/asn_charset.c,v 6.0 1991/12/18 20:15:43 jpo Rel $";
  5. # endif
  6.  
  7. /*
  8.  * $Header: /xtel/pp/pp-beta/Format/asn/RCS/asn_charset.c,v 6.0 1991/12/18 20:15:43 jpo Rel $
  9.  *
  10.  * $Log: asn_charset.c,v $
  11.  * Revision 6.0  1991/12/18  20:15:43  jpo
  12.  * Release 6.0
  13.  *
  14.  */
  15.  
  16.  
  17.  
  18. #include  "head.h"
  19. #include  "charset.h"
  20. #include  "asn.h"
  21.  
  22. static CHARSET    *Iset, *Oset;
  23. extern int    MnemonicsRequired;
  24.  
  25.  
  26.  
  27. /* ------------------------  Start Routine  --------------------------------- */
  28.  
  29.  
  30.  
  31.  
  32. asn_charset(inset, outset, body)
  33. char        *inset;        /* -- in character set -- */
  34. char        *outset;    /* -- out character set -- */
  35. ASNBODY        *body;        /* -- body to be converted -- */
  36. {
  37.     ASNBODY    *bp, *bak;
  38.  
  39.     PP_TRACE(("asn_charset (%s, %s)", inset, outset));
  40.  
  41.     if ((Iset = getchset (inset, DEFAULT_ESCAPE)) == NULL) {
  42.         PP_LOG (LLOG_EXCEPTIONS,
  43.             ("Unknown input charset %s", inset));
  44.         exit (1);
  45.     }
  46.  
  47.     if ((Oset = getchset (outset, DEFAULT_ESCAPE)) == NULL) {
  48.         PP_LOG (LLOG_EXCEPTIONS,
  49.             ("Unknown output charset %s", outset));
  50.         exit (1);
  51.     }
  52.  
  53.  
  54.     for (bp = body; bp; bp = bp -> next)
  55.         call_strncnv (bp); 
  56. }
  57.  
  58.  
  59.  
  60.  
  61. /* ------------------------  Static Routines  ------------------------------- */
  62.  
  63.  
  64.  
  65.  
  66. static call_strncnv (bp)
  67. ASNBODY    *bp;
  68. {
  69.     char        *cp;
  70.     int        blen, length; 
  71.  
  72.     PP_TRACE (("call_strncnv (%d)", bp -> length));
  73.  
  74.     if (bp -> length == 0 && bp -> line == 0) {
  75.         PP_LOG (LLOG_EXCEPTIONS, ("Error unable to convert"));
  76.         exit (1);
  77.     }
  78.         
  79.     blen = (bp -> length * 3) + 4;
  80.     cp = malloc (blen);
  81.     bzero (cp, blen);
  82.  
  83.     switch (MnemonicsRequired) {
  84.     case TRUE:
  85.         length = strncnv  (Oset, Iset, (CHAR8U*)cp, 
  86.                   (CHAR8U*) bp->line, blen, TRUE);
  87.         break;
  88.     default:
  89.         length = strncnv (Oset, Iset, (CHAR8U*)cp, 
  90.                  (CHAR8U*) bp->line, bp -> length, FALSE);
  91.         break;
  92.     }
  93.  
  94.     free (bp -> line);
  95.     bp -> line = realloc (cp, length);
  96.     bp -> length = length;
  97. }
  98.